package com.sy.controller;

import com.sun.net.httpserver.Authenticator;
import com.sy.bean.Dict;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
@Api(tags = "字典")
public class DictController extends BaseController {

    @Autowired
    DictService service;

    @ApiOperation("字典列表")
    @GetMapping("/dict/list")
    public ResultBean query (@RequestParam(value="code") String code){
        List<Dict> list = service.queryD(code);
        return success("字典",list);
    }

    @ApiOperation("字典新增")
    @PutMapping("/dict/save")
    public ResultBean save (@RequestBody Dict dict){
        int save = service.save(dict);
        return save>0?success("保存成功"):fail("保存失败");
    }

    @ApiOperation("字典删除")
    @DeleteMapping("/dict/delete")
    public ResultBean delete (@RequestParam(name = "id") int id){
        int save = service.delete(id);
        return save>0?success("删除成功"):fail("删除失败");
    }

    @ApiOperation("字典修改")
    @PostMapping("/dict/update")
    public ResultBean update (int id,String name){
        Dict dict=new Dict();
        dict.setId(id);
        dict.setName(name);
        int save = service.update(dict);
        return save>0?success("成功"):fail("失败");
    }
}
